#pragma once
#include<Arduino.h>

namespace ganix {
    namespace string_ext {
        String join(String delimiter, String *array, int size) {
            String rtn = "";
            for (int i=0; i<size; i++) {
                rtn += array[i];
                if (i < size -1) {
                    rtn += delimiter;
                }
            }
            return rtn;
        }

        String url_encode(const String& str) {
            String result = "";
            int length = str.length();
            for (int i = 0; i < length; i++)
            {
                if (isalnum((unsigned char)str[i]) || 
                    (str[i] == '-') ||
                    (str[i] == '_') || 
                    (str[i] == '.') || 
                    (str[i] == '~'))
                    result += str[i];
                else
                {
                    char buf[5];
                    result += '%';
                    itoa(str[i], buf, 16);
                    result += buf;
                }
            }
            return result;
        }
    } // namespace string_ext
} // namespace ganix
